﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:componentmodel="clr-namespace:System.ComponentModel;assembly=PresentationFramework"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <!-- Colors -->
    <SolidColorBrush x:Key="RibbonBackgroundBrush" Color="#BFDBFF"/>
    <LinearGradientBrush x:Key="RibbonBrush" ColorInterpolationMode="ScRgbLinearInterpolation" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#D7E3F2" Offset="0.1"/>
        <GradientStop Color="#E3F4FF" Offset="1"/>
    </LinearGradientBrush>
    <SolidColorBrush x:Key="RibbonBorderBrush" Color="#9EBFDB"/>
    <SolidColorBrush x:Key="RibbonTextBrush" Color="#20426F"/>
    <LinearGradientBrush x:Key="RibbonTabHeaderBrush"  ColorInterpolationMode="ScRgbLinearInterpolation" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#E4EFFD" Offset="0"/>
        <GradientStop Color="#D7E3F2" Offset="1"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="RibbonTabHeaderInactiveHighlightBrush" ColorInterpolationMode="ScRgbLinearInterpolation" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#E4EFFD" Offset="0"/>
        <GradientStop Color="#80FFC000" Offset="0.7"/>
        <GradientStop Color="#DCE8F8" Offset="1"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="RibbonTabHeaderActiveHighlightBrush" ColorInterpolationMode="ScRgbLinearInterpolation" StartPoint="0,0" EndPoint="0,1">     
        <GradientStop Color="#80FFC000" Offset="0.0"/>
        <GradientStop Color="#E4EFFD" Offset="0.2"/>
        <GradientStop Color="#DCE8F8" Offset="1"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="RibbonGroupBrush" ColorInterpolationMode="ScRgbLinearInterpolation" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#DBE6F3" Offset="0"/>
        <GradientStop Color="#D7E7F5" Offset="1"/>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="RibbonGroupBorderBrush" ColorInterpolationMode="ScRgbLinearInterpolation" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#C5D2DF" Offset="0"/>
        <GradientStop Color="#9EBFDB" Offset="1"/>
    </LinearGradientBrush>
    <SolidColorBrush x:Key="RibbonGroupHeaderBrush" Color="#200077EF"/>
    <SolidColorBrush x:Key="RibbonGroupTextBrush" Color="#3E6AAA"/>
    <SolidColorBrush x:Key="RibbonGroupBorderHighlightBrush" Color="White"/>
    <LinearGradientBrush x:Key="RibbonGroupHighlightBrush"  ColorInterpolationMode="ScRgbLinearInterpolation" StartPoint="0,0" EndPoint="0,1">
        <GradientStop Color="#E4EFFD" Offset="0"/>
        <GradientStop Color="#DCE8F8" Offset="1"/>
    </LinearGradientBrush>

    <!-- Set the default colour for all text. -->
    <Style TargetType="TextBlock">
        <Setter Property="Foreground" Value="{DynamicResource RibbonTextBrush}"/>
    </Style>

    <!-- ToolBarTrays become contains for Ribbon Groups -->
    <Style TargetType="ToolBarTray">
        <Setter Property="IsLocked" Value="True"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Orientation" Value="Horizontal"/>
    </Style>

    <!-- TabItems become Ribbon Tabs -->
    <Style TargetType="{x:Type TabItem}" x:Key="RibbonTabStyle">
        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock Text="{Binding}" Padding="2" TextAlignment="Center"/>
                    </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderBrush" Value="{DynamicResource RibbonBorderBrush}"/>
        <Setter Property="BorderThickness" Value="1,1,1,0"/>
        <Setter Property="Background" Value="{DynamicResource RibbonTabHeaderBrush}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TabItem">
                    <Border Background="{TemplateBinding Background}" BorderThickness="1,1,1,0" CornerRadius="5,5,0,0" BorderBrush="{TemplateBinding BorderBrush}" Margin="0,2,0,-2">
                        <ContentPresenter x:Name="_content" ContentSource="Header" Margin="12,1"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <Style.Triggers>

            <Trigger Property="IsSelected" Value="False">
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="BorderBrush" Value="Transparent"/>
                <Setter Property="ClipToBounds" Value="True"/>
            </Trigger>

            <!-- Tab Header has the mouse over but is not currently the selected one. -->
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver" Value="True"/>
                    <Condition Property="IsSelected" Value="False"/>
                </MultiTrigger.Conditions>
                <Setter Property="Background" Value="{DynamicResource RibbonTabHeaderInactiveHighlightBrush}"/>
            </MultiTrigger>

            <!-- Mouse over the seleted tab header. -->
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver" Value="True"/>
                    <Condition Property="IsSelected" Value="True"/>
                </MultiTrigger.Conditions>
                <Setter Property="Background" Value="{DynamicResource RibbonTabHeaderActiveHighlightBrush}"/>
            </MultiTrigger>

        </Style.Triggers>

        <Style.Resources>
            <!-- ToolBars become Ribbon Groups -->
            <Style TargetType="ToolBar">
                <Setter Property="Background" Value="{DynamicResource RibbonGroupBrush}"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="BorderBrush" Value="{DynamicResource RibbonGroupBorderBrush}"/>
                <!-- Template for the Ribbon Group -->
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ToolBar">
                            <Border BorderBrush="{DynamicResource RibbonGroupBorderHighlightBrush}" Padding="0,0,1,1" CornerRadius="4" BorderThickness="0,0,1,1" Margin="0,0,4,0">
                                <Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" CornerRadius="4">
                                    <Border BorderBrush="{DynamicResource RibbonGroupBorderHighlightBrush}" CornerRadius="4" BorderThickness="1,1,0,0">
                                        <Border Background="{TemplateBinding Background}" CornerRadius="4">
                                            <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Bottom">
                                                <ItemsPresenter Margin="2,0,2,0"/>
                                                <Border Padding="4,1,4,2" Background="{DynamicResource RibbonGroupHeaderBrush}" BorderBrush="{DynamicResource RibbonBorderBrush}" BorderThickness="0,1,0,0" CornerRadius="0,0,4,4">
                                                    <ContentPresenter ContentSource="Header" HorizontalAlignment="Center"/>
                                                </Border>
                                            </StackPanel>
                                        </Border>
                                    </Border>
                                </Border>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="HeaderTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <TextBlock Text="{Binding}" Foreground="{DynamicResource RibbonGroupTextBrush}" FontSize="11"/>
                            </DataTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <WrapPanel Orientation="Vertical" Height="70"/>
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
                <Style.Resources>
                    <!-- Menus in ToolBars have a transparent background to look like Buttons. -->
                    <Style x:Key="{x:Static ToolBar.MenuStyleKey}" TargetType="Menu">
                        <Setter Property="Background" Value="Transparent"/>
                    </Style>
                    <!-- Style for buttons that overrides the ContentTemplate to allow for terse ImageButton creation. -->
                    <Style TargetType="{x:Type Button}" x:Key="{x:Static ToolBar.ButtonStyleKey}">
                        <Setter Property="Margin" Value="0"/>
                        <Setter Property="Padding" Value="0"/>
                        <Setter Property="HorizontalAlignment" Value="Left"/>
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate DataType="{x:Type Button}">
                                    <Border x:Name="Border" CornerRadius="4">
                                        <StackPanel x:Name="PART_panel" Orientation="Horizontal">
                                            <Image x:Name="PART_image"  Width="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Source.PixelWidth}" Margin="4,0,0,0" >
                                                <Image.Source>
                                                        <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=Button}" Path="Tag"/>
                                                </Image.Source>
                                            </Image>
                                            <!--<TextBlock x:Name="PART_text" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Content}" VerticalAlignment="Center" Margin="3,0,4,0"/>-->
                                            <ContentControl x:Name="PART_text" Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=Content}" Margin="3,0,4,0"  VerticalAlignment="Center" />
                                        </StackPanel>
                                    </Border>
                                    <DataTemplate.Triggers>
                                        <DataTrigger Binding="{Binding ElementName=PART_image, Path=Source.PixelHeight}" Value="48">
                                            <Setter TargetName="PART_panel" Property="Orientation" Value="Vertical"/>
                                            <Setter TargetName="PART_text" Property="HorizontalAlignment" Value="Center"/>
                                        </DataTrigger>
                                        <MultiDataTrigger>
                                            <MultiDataTrigger.Conditions>
                                                <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=IsEnabled}" Value="false"/>
                                                <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Button}, Path=(componentmodel:DesignerProperties.IsInDesignMode)}" Value="false"/>
                                            </MultiDataTrigger.Conditions>
                                            <Setter TargetName="PART_panel" Property="Opacity" Value="0.5"/>
                                        </MultiDataTrigger>
                                    </DataTemplate.Triggers>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Style.Resources>
                <!-- Highlight the ribbon group on Mouse Over -->
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="{DynamicResource RibbonGroupHighlightBrush}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

        </Style.Resources>
    </Style>

    <!-- TabControl becomes the Ribbon Bar -->
    <Style TargetType="TabControl" x:Key="RibbonBarStyle">
        <Setter Property="Margin" Value="0"/>
        <Setter Property="BorderThickness" Value="1,1,1,1"/>
        <Setter Property="BorderBrush" Value="{DynamicResource RibbonBorderBrush}"/>
        <Setter Property="ItemContainerStyle" Value="{StaticResource RibbonTabStyle}"/>
        <Setter Property="Background" Value="{DynamicResource RibbonBrush}"/>
        <!--<Setter Property="Background" Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=SelectedItem.Background}"/>-->
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TabControl">
                    <StackPanel Orientation="Vertical" SnapsToDevicePixels="True">
                        <Border Background="{DynamicResource RibbonBackgroundBrush}" Panel.ZIndex="5">
                            <ItemsPresenter Margin="10,0,0,0"/>
                        </Border>
                        <Border Padding="2,0,2,2" Background="{DynamicResource RibbonBackgroundBrush}">
                            <Border BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="4" Background="{TemplateBinding Background}" Padding="3">

                                <!--<controls:TabContentBorder TabControl="{Binding RelativeSource={RelativeSource TemplatedParent}}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="4" Background="{TemplateBinding Background}" Padding="3">-->
                                <ContentPresenter ContentSource="SelectedContent"/>
                                <!--</controls:TabContentBorder>-->
                            </Border>
                        </Border>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

</ResourceDictionary>